package JDBCUtil;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class DelJDBC {
    public static void main(String[] args) throws SQLException {
        //打开数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java110?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("zkzsa123");
        //连接数据源
        Connection connection = dataSource.getConnection();

        String sql = "delete from student where id =?";
        PreparedStatement statement = connection.prepareStatement(sql);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的ID");
        int id = scanner.nextInt();
        statement.setObject(1,id);
        int i = statement.executeUpdate();
        System.out.println("i:"+i);
        statement.close();
        connection.close();
    }
}
